from utalcanvas import *
from time import *

#### Pruebas



def move_element( elementId ):
    sleep(0.5)
    move( elementId, 10, 0)
    sleep(0.5)
    move( elementId, 0, 10)
    sleep(0.5)
    move( elementId, -10, 0)
    sleep(0.5)
    move( elementId, 0, -10)
    sleep(0.5)
    erase(elementId)

def move_elements_one_by_one( listId, idTag ):
    sleep(0.5)
    for pointId in listId:
        move( pointId, 10, 10 )
        sleep(0.5)
        
    for i in range(idTag):
        move( "tag"+str(i), 10, 10 )
        sleep(0.5)
        
    for i in range(idTag):
        erase( "tag"+str(i) )
        sleep(0.5)

def move_elements_by_tag( tag ):
    sleep(0.5)
    move( tag, -10, -10 )
    sleep(0.5)
    erase(tag)
    sleep(0.5)

def remove_all():
    sleep(0.5)
    erase()
    
def change_size_and_viewport():
    sleep(0.5)
    window_size( 800, 600 )
    sleep(0.5)
    window_coordinates( 0, 0, 800, 600 )
    for i in range(0, 35):
        window_coordinates( 0+i*5, 0, 800+i*5, 600 )
        sleep(0.05)
    erase()

def initialize():
    window_size( 400, 300 )
    window_coordinates( 0, 0, 400, 300 )

"""
Probar la funcionalidad de los puntos
"""
def test_points():
    initialize()
    pointId = create_point( 200, 150, "blue", "tag" )
    move_element(pointId)
    
    idTag = 0
    listId = []
    for i in range(-10, 10, 10):
        for j in range(-10, 10, 10):
            pointId = create_point( 200+i, 150+j, "gold", "tag"+str(idTag) )
            listId += [pointId]
            idTag += 1
    
    move_elements_one_by_one( listId, idTag )
    
    for i in range(-10, 10, 10):
        for j in range(-10, 10, 10):
            create_point( 200+i, 150+j, "gold", "tag" )
    
    move_elements_by_tag("tag")
    
    for y in range( 0, 300, 10 ):
        for x in range( 0, 400, 10 ):
            create_point( x, y, "black" )
    remove_all()
    
    for y in range( 0, 300, 10 ):
        for x in range( 0, 400, 10 ):
            create_point( x, y, create_color(255*(x/400.0),255*(y/300.0),100) )
    change_size_and_viewport()

"""
Probar la funcionalidad de las lineas
"""
def test_lines():    
    initialize()
    lineId = create_line( 100,150, 300, 150, "orange" )
    move_element(lineId)
    
    idTag = 0
    listId = []
    for i in range(50, 250, 10):
        lineId = create_line( 100,i, 300, i, "cyan", "tag"+str(idTag) )
        listId += [lineId]
        idTag += 1
    move_elements_one_by_one( listId, idTag )
    
    for i in range(50, 250, 10):
        create_line( 100,i, 300, i, "yellow", "tag" )
    move_elements_by_tag("tag")
    
    for i in range( 0, 400, 10 ):
        create_line( i, 0, i, 300, "green" )
    for i in range( 0, 300, 10 ):
        create_line( 0, i, 400, i, "green" )
    remove_all()
    
    for i in range( 0, 400, 10 ):
        create_line( i, 0, i, 300, "green" )
    for i in range( 0, 300, 10 ):
        create_line( 0, i, 400, i, "green" )
    change_size_and_viewport()

def test_rectangles():
    initialize()
    rectangleId = create_rectangle( 100,50, 300, 250, "orange" )
    move_element(rectangleId)
    
    idTag = 0
    listId = []
    for i in range(0, 100, 10):
        rectangleId = create_rectangle( 100+i, 50+i, 300-i, 250-i, "cyan", "tag"+str(idTag) )
        listId += [rectangleId]
        idTag += 1
    move_elements_one_by_one( listId, idTag )
    
    for i in range(0, 100, 10):
        create_rectangle( 100+i, 50+i, 300-i, 250-i, "cyan", "tag" )
    move_elements_by_tag("tag")
    
    for i in range(0, 100, 10):
        create_rectangle( 100+i, 50+i, 300-i, 250-i, "red" )
    remove_all()
    
    for i in range(0, 100, 10):
        create_rectangle( 100+i, 50+i, 300-i, 250-i, "red" )
    change_size_and_viewport()

def test_filled_rectangles():
    initialize()
    rectangleId = create_filled_rectangle( 100,50, 300, 250, "orange", "white" )
    move_element(rectangleId)
    
    idTag = 0
    listId = []
    for i in range(0, 100, 10):
        rectangleId = create_filled_rectangle( 100+i, 50+i, 300-i, 250-i, "cyan", create_color( 255-255*(i/100.0), 0, 0 ), "tag"+str(idTag)  )
        listId += [rectangleId]
        idTag += 1
    move_elements_one_by_one( listId, idTag )
    
    for i in range(0, 100, 10):
        create_filled_rectangle( 100+i, 50+i, 300-i, 250-i, "cyan", create_color( 255-255*(i/100.0), 0, 0 ), "tag"  )
    move_elements_by_tag("tag")
    
    for i in range(0, 100, 10):
        create_filled_rectangle( 100+i, 50+i, 300-i, 250-i, "cyan", create_color( 255-255*(i/100.0), 0, 0 )  )
    remove_all()    

    for i in range(0, 100, 10):
        create_filled_rectangle( 100+i, 50+i, 300-i, 250-i, "cyan", create_color( 255-255*(i/100.0), 0, 0 )  )
    change_size_and_viewport()

def test_circles():
    initialize()
    circleId = create_circle( 200, 150, 100, "orange" )
    move_element(circleId)

    idTag = 0
    listId = []
    for i in range(0, 90, 10):
        circleId = create_circle( 200, 150, 100-i, "cyan", "tag"+str(idTag)  )
        listId += [circleId]
        idTag += 1
    move_elements_one_by_one( listId, idTag )
    
    for i in range(0, 90, 10):
        create_circle( 200, 150, 100-i, "blue", "tag" )
    move_elements_by_tag("tag")
    
    for i in range(0, 90, 10):
        create_circle( 200, 150, 100-i, "blue" )
    remove_all()
    
    for i in range(0, 90, 10):
        create_circle( 250, 150, 100-i, "blue"  )
    change_size_and_viewport()

def test_filled_circles():
    initialize()
    circleId = create_filled_circle( 200, 150, 100, "orange", "mediumpurple2" )
    move_element(circleId)

    idTag = 0
    listId = []
    for i in range(0, 90, 10):
        circleId = create_filled_circle( 200, 150, 100-i, "hotpink1", create_color( 255-255*(i/90.0), 0, 0 ), "tag"+str(idTag) )
        listId += [circleId]
        idTag += 1
    move_elements_one_by_one( listId, idTag )
    

    for i in range(0, 90, 10):
        create_filled_circle( 200, 150, 100-i, "hotpink1", create_color( 255-255*(i/90.0), 0, 0 ), "tag" )
    move_elements_by_tag("tag")
    
    for i in range(0, 90, 10):
        create_filled_circle( 200, 150, 100-i, "hotpink1", create_color( 255-255*(i/90.0), 0, 0 ) )
    remove_all()
    
    for i in range(0, 90, 10):
        create_filled_circle( 200, 50, 100-i, "hotpink1", create_color( 255-255*(i/90.0), 0, 0 ) )
    change_size_and_viewport()

def test_texts():
    initialize()
    create_line( 0, 150, 400, 150, "red" )
    create_line( 200, 0, 200, 300, "red" )
    anchorsList = [ "CENTER", "N", "NW", "W", "SW", "S", "SE", "E", "NE" ]
    for anchor in anchorsList:
        idText = create_text( 200, 150, "Hola mundo!!!", 10, anchor, "blue" )        
        sleep(1)
        erase(idText)
    erase()
        
    for i in range( 0, 200, 20 ):
        create_text( i, i, "Hola mundo!!!", 10, anchor.lower(), "paleturquoise3" )
        sleep(0.5)
    change_size_and_viewport()
        
def test1_mouse():
    initialize()
    window_coordinates( 0, 0, 1000, 1000 )
    t1 = time()
    t2 = time()
    while t2 - t1 < 30:
        boton, x, y = mouse_state()
        textInfo = "( " + str(boton) + " , " + str(x) + " , " + str(y) + " )"
        text = create_text( 500, 500, textInfo, 35 )
        sleep(0.05)
        erase(text)
        t2 = time()
    erase()
        
def test2_mouse():
    initialize()
    t1 = time()
    t2 = time()
    rectangle = create_filled_rectangle( 190, 140, 210, 160 )
    while t2 - t1 < 10:
        boton, x, y = mouse_state()
        if x != None and y != None:
            erase(rectangle)
            rectangle = create_filled_rectangle( x-10, y-10, x+10, y+10 )
            sleep(1.0/24)
            t2 = time()
    erase()

def test_keys():
    initialize()
    point = create_point( 200, 150 )
    finished = False
    while not finished:
        key = keypressed(2)
        if key == Key_Escape:
            finished = True
        elif key == Key_Up: #arriba
            move(point, 0, 1)
        elif key == Key_Down: #abajo
            move(point, 0, -1)
        elif key == Key_Left: #izquierda
            move(point, -1, 0)
        elif key == Key_Right: #derecha
            move(point, 1, 0)
            
    erase()
 
def test_colors():
    lista = ["yellow", "olive", "LightCyan3", "LightCyan2", "LightCyan4", "gray32", "gray33", 
             "gray30", "gray31", "gray36", "gray37", "gray34", "gray35", "aquamarine4", "gray38", 
             "gray39", "aquamarine2", "CadetBlue4", "CadetBlue3", "CadetBlue2", "CadetBlue1", 
             "VioletRed1", "VioletRed2", "VioletRed3", "VioletRed4", "brown", "gray8", "gray9", 
             "gray2", "cyan", "navajo", "gray6", "gray7", "gray4", "gray5", "dim", "gray99", 
             "dodger", "PaleGreen1", "PaleGreen3", "PaleGreen2", "PaleGreen4", "lavender", 
             "chartreuse3", "chartreuse2", "chartreuse4", "blue", "maroon4", "maroon3", 
             "maroon2", "maroon1", "gold3", "gold2", "indian", "gold4", "coral4", "gray60", 
             "firebrick3", "firebrick2", "firebrick1", "firebrick4", "sienna", "lime", "gray55", 
             "gainsboro", "peru", "LightBlue2", "LightBlue3", "LightBlue1", "LightBlue4", "red4", 
             "chocolate", "HotPink3", "HotPink2", "HotPink1", "HotPink4", "moccasin", "chocolate1", 
             "chocolate2", "chocolate3", "gray69", "gray68", "gray65", "gray64", "gray67", "gray66", 
             "gray61", "plum", "gray63", "gray62", "seashell2", "seashell3", "tan", "magenta", 
             "seashell4", "pink", "SteelBlue1", "SteelBlue3", "SteelBlue2", "SteelBlue4", 
             "gray56", "floral", "khaki4", "khaki1", "khaki2", "khaki3", "salmon1", "light", 
             "salmon3", "salmon2", "salmon4", "linen", "green", "brown2", "brown3", "brown1", 
             "brown4", "orange4", "midnight", "orange3", "orange2", "gray3", "gray1", "yellow4", 
             "yellow3", "yellow2", "MediumOrchid3", "orange", "MediumOrchid2", "OliveDrab1", 
             "OliveDrab2", "forest", "cornflower", "SkyBlue4", "slate", "SkyBlue1", "SkyBlue3", 
             "SkyBlue2", "cyan2", "cyan3", "gray23", "goldenrod", "gray25", "gray24", "cyan4", 
             "gray26", "gray29", "SlateGray4", "navy", "sandy", "gray94", "gray95", "gray97", 
             "gray90", "gray91", "gray92", "gray93", "gray98", "cornsilk", "red", "DarkOrchid4", 
             "blue2", "blue4", "DarkOrchid2", "DarkOrchid3", "tomato4", "tomato3", "tomato2", 
             "DarkSlateGray1", "DarkSlateGray2", "DarkSlateGray3", "DarkSlateGray4", "gray82", 
             "burlywood", "white", "tomato", "gray79", "RoyalBlue4", "RoyalBlue1", "RoyalBlue3", 
             "RoyalBlue2", "MistyRose3", "MistyRose2", "MistyRose4", "royal", "steel", "sea", 
             "burlywood1", "turquoise2", "turquoise1", "burlywood2", "mint", "burlywood4", 
             "turquoise4", "snow", "gray58", "gray59", "IndianRed4", "purple4", "gray52", "gray53", 
             "purple1", "IndianRed1", "IndianRed2", "IndianRed3", "DarkOrchid1", "thistle3", 
             "thistle2", "SpringGreen2", "SpringGreen3", "SpringGreen4", "thistle4", "LightPink2", 
             "LightPink3", "LightPink1", "LightPink4", "MediumPurple1", "MediumPurple2", 
             "MediumPurple3", "MediumPurple4", "lawn", "OrangeRed3", "OrangeRed2", "gold", 
             "OrangeRed4", "NavajoWhite4", "NavajoWhite2", "NavajoWhite3", "LightGoldenrod4", 
             "LightGoldenrod1", "LightGoldenrod3", "LightGoldenrod2", "gray21", "green4", 
             "green3", "green2", "black", "gray20", "orchid4", "DodgerBlue2", "DodgerBlue3", 
             "DodgerBlue4", "orchid1", "orchid2", "orchid3", "DarkSeaGreen4", "DarkSeaGreen3", 
             "DarkSeaGreen2", "DarkSeaGreen1", "bisque4", "MediumOrchid4", "MediumOrchid1", 
             "bisque2", "bisque3", "gray", "blanched", "plum4", "plum3", "plum2", "plum1", 
             "powder", "thistle", "violet", "LightSalmon4", "LightSalmon2", "LightSalmon3", 
             "honeydew", "gray18", "gray19", "gray14", "gray15", "gray16", "gray17", "gray10", 
             "gray11", "gray12", "gray13", "AntiqueWhite3", "AntiqueWhite2", "AntiqueWhite1", 
             "AntiqueWhite4", "gray83", "sienna4", "gray81", "gray80", "sienna1", "gray86", 
             "sienna3", "sienna2", "gray89", "gray88", "magenta4", "gray87", "LightSteelBlue1", 
             "magenta3", "magenta2", "PeachPuff4", "seashell", "PeachPuff2", "PeachPuff3", 
             "aquamarine", "LemonChiffon2", "tan4", "tan2", "tan1", "LemonChiffon4", "OliveDrab4", 
             "deep", "SlateGray3", "LightSkyBlue4", "LightSkyBlue1", "LightSkyBlue2", 
             "LightSkyBlue3", "LightYellow2", "LightYellow3", "LightYellow4", "goldenrod4", 
             "goldenrod1", "goldenrod2", "goldenrod3", "turquoise3", "burlywood3", "ivory3", 
             "ivory2", "ivory4", "SlateGray1", "SlateGray2", "RosyBrown4", "RosyBrown3", 
             "RosyBrown2", "RosyBrown1", "papaya", "gray85", "gray84", "LavenderBlush3", 
             "LavenderBlush2", "LavenderBlush4", "pink1", "pink3", "pink2", "pink4", "gray47", 
             "gray46", "gray45", "gray44", "gray43", "gray42", "gray40", "gray49", "gray48", 
             "azure3", "azure2", "azure4", "firebrick", "SlateBlue4", "sky", "SlateBlue2", 
             "SlateBlue1", "chartreuse", "rosy", "DarkOliveGreen4", "turquoise", "DarkOliveGreen1", 
             "DarkOliveGreen3", "DarkOliveGreen2", "dark", "gray50", "gray22", "gray51", "gray27", 
             "DarkGoldenrod4", "gray54", "alice", "DarkGoldenrod2", "DarkGoldenrod3", "purple3", 
             "gray28", "purple2", "antique", "old", "spring", "DarkGoldenrod1", "DarkOrange4", 
             "pale", "DarkOrange3", "orchid", "purple", "wheat4", "wheat1", "wheat3", "wheat2", 
             "coral3", "coral2", "coral1", "thistle1", "bisque", "DeepPink3", "DeepPink2", 
             "khaki", "wheat", "DeepPink4", "salmon", "PaleVioletRed4", "PaleVioletRed1", 
             "PaleVioletRed2", "PaleVioletRed3", "PaleTurquoise4", "PaleTurquoise3", 
             "PaleTurquoise2", "PaleTurquoise1", "saddle", "coral", "hot", "beige", "azure", 
             "honeydew2", "honeydew3", "honeydew4", "cadet", "gray57", "snow4", "snow2", 
             "snow3", "SeaGreen3", "SeaGreen2", "SeaGreen1", "gray78", "DebianRed", "gray76", 
             "gray77", "gray74", "gray75", "gray72", "gray73", "gray70", "gray71", "ivory", 
             "medium", "LemonChiffon3", "DeepSkyBlue4", "DeepSkyBlue3", "DeepSkyBlue2", "misty", 
             "cornsilk4", "cornsilk2", "cornsilk3", "red3", "LightSteelBlue2", "LightSteelBlue3", 
             "LightSteelBlue4", "red2", "maroon", "lemon", "peach", "DarkOrange1", "DarkOrange2", 
             "SlateBlue3", "ghost"]
    window_size( 50, 50 )
    for i in lista:
        window_style( "titulo", i )
        sleep(0.1)
        

show_window()
test_points()
test_lines()
test_rectangles()
test_filled_rectangles()
test_circles()
test_filled_circles()
test_texts()
test1_mouse()
test2_mouse()
test_keys()
test_colors()
close_window()




